<?php

namespace addons\TinyShare\common\models\forms;

use common\enums\SortEnum;
use yii\base\Model;

/**
 * 内容快速搜索表单
 *
 * Class ContentSearch
 * @package addons\TinyShare\common\models\forms
 * @author jackey <270499458@qq.com>
 */
class ContentSearch extends Model
{
    /*-- 查询 --*/

    public $keyword;
    public $cate_id;
	public $position = 1;

    /*-- 排序 --*/
	
	public $like;
    public $collection;
    public $view;

    public $page_size = 10;

    /**
     * @return array
     */
    public function rules()
    {
        return [
            [['tag_id', 'cate_id', 'position', 'page_size'], 'integer'],
            [['like', 'collection', 'view' ,'keyword'], 'string'],
        ];
    }

    /**
     * @return array
     */
    public function getOrderBy()
    {
        // 排序
        $order = [];

        $this->collection == SortEnum::ASC && $order[] = 'collection ' . SortEnum::ASC;
        $this->collection == SortEnum::DESC && $order[] = 'collection ' . SortEnum::DESC;
        $this->view == SortEnum::ASC && $order[] = 'view ' . SortEnum::ASC;
        $this->view == SortEnum::DESC && $order[] = 'view ' . SortEnum::DESC;
        $this->like == SortEnum::ASC && $order[] = 'like ' . SortEnum::ASC;
        $this->like == SortEnum::DESC && $order[] = 'like ' . SortEnum::DESC;

        return $order;
    }
}